import {
  App
} from './App';
import {
  Header
} from '../components/header';
import {
  DetailBoard
} from '../components/detail_board/index';
import {
  Footer
} from '../components/footer';


import tools from '../utils/tools';
import {
  DetailModel
} from '../models/detail';

class Detail extends App {
  constructor($, app) {
    super($, app, {
      swiper: false,
      phone: true,
      field: true
    });

    this.phoneId = tools.getUrlQueryValue('id');

  }

  async render() {
    const data = await this.getPhoneInfo(this.phoneId);

    new Header(this.$app, this.cache.fieldDatas, this.cache.phoneDatas).init();
    new DetailBoard(this.$app, data).init();
    new Footer(this.$app).init();

    $('body').prepend(this.$app);
  }

  getPhoneInfo(id) {
    const detailModel = new DetailModel();
    return detailModel.getPhoneInfo(id);

    // console.log(data);
    //{id: '11', field: 'Note', phone_name: 'Redmi Note 7', slogan: '4800万拍照千元机 / 品质“小金刚”，18个月超长质保 / “满血版”骁龙660处理器 / 4000mAh 大电量 / 6.3" 水滴全面屏 / USB-C 接口，方便耐用 / 支持快充 4 协议', default_price: '1499', …}
  }

}

new Detail(jQuery);